package edu.scu.declaresys.vo;

import edu.scu.declaresys.dao.util.Column;
import edu.scu.declaresys.dao.util.FieldWalker;
import edu.scu.declaresys.dao.util.Table;


/**
 * 
 * @author: zt
 * @since : 2013-7-5
 */
@Table(code=User.T_TABLE)
public class User implements java.io.Serializable
{
	private static final long	serialVersionUID	= -9144753584981333591L;
	//
	// table column name.
	//
	public static final String	T_TABLE				= "user";
	public static final String	T_ID				= "id";
	public static final String	T_PROVINCE_ID		= "provinceId";
	public static final String	T_CITY_ID			= "cityId";
	public static final String	T_COUNTY_ID			= "countyId";
	public static final String	T_LEVEL				= "level";
	public static final String	T_ROLE				= "role";
	public static final String	T_LOGIN_NAME		= "loginName";
	public static final String	T_PSWD				= "pswd";
	public static final String	T_UNIT_NAME			= "unitName";
	public static final String	T_ADDRESS			= "address";
	public static final String	T_PHONE				= "phone";
	public static final String	T_EMAIL				= "email";
	//
	// role
	//
	public static final int ROLE_PROJECT_DECLARE = 1;
	public static final String ROLE_PROJECT_DECLARE_NAME = "申报人员";
	
	public static final int ROLE_PROJECT_RECOMMEND = 2;
	public static final String ROLE_PROJECT_RECOMMEND_NAME = "推荐人员";
	
	public static final int ROLE_PROJECT_AUDIT = 3;
	public static final String ROLE_PROJECT_AUDIT_NAME ="审批人员";
	
	public static final int ROLE_SYS_ADMIN = 4;
	public static final String ROLE_SYS_ADMIN_NAME = "系统管理员";
	//
	//
	//
	public static final int NULL_USER_ID = -1;
	public static final int PROVINCE_RCMD_USER_ID = 15;
	public static final int PROVINCE_AUDIT_USER_ID = 16;
	//
	// Fields
	//
	@Column(code = T_ID)
	private Integer				id;
	
	@Column(code=T_PROVINCE_ID)
	private Integer provinceId;
	
	@Column(code=T_CITY_ID)
	private Integer cityId;
	
	@Column(code = T_COUNTY_ID)
	private Integer				countyId;
	
	/**
	 * 由地区级别判断。
	 */
	@Column(code = T_LEVEL)
	private Integer level;
	
	@Column(code=T_ROLE)
	private Integer role;
	
	@Column(code = T_LOGIN_NAME)
	private String				loginName;
	
	@Column(code = T_PSWD)
	private String				pswd;
	
	@Column(code = T_UNIT_NAME)
	private String				unitName;
	
	@Column(code = T_ADDRESS)
	private String				address;
	
	@Column(code = T_PHONE)
	private String				phone;
	
	@Column(code = T_EMAIL)
	private String				email;
	
	//
	// References
	//
	private Area province;
	private Area city;
	private Area county;
	

	//
	// Constructors
	//
	/** default constructor */
	public User()
	{
	}

	public User(Integer id, Integer provinceId, Integer cityId,
			Integer countyId, Integer level, Integer role, String loginName,
			String pswd, String unitName, String address, String phone,
			String email)
	{
		super();
		this.id = id;
		this.provinceId = provinceId;
		this.cityId = cityId;
		this.countyId = countyId;
		this.level = level;
		this.role = role;
		this.loginName = loginName;
		this.pswd = pswd;
		this.unitName = unitName;
		this.address = address;
		this.phone = phone;
		this.email = email;
	}


	//
	// Override functions.
	//
	public String toString()
	{
		return FieldWalker.makeNonstaticFields(this, FieldWalker.WITHOUT_NULL);
	}
	
	@Override
	public int hashCode()
	{
		return id.hashCode();
	}

	@Override
	public boolean equals(Object obj)
	{
		if(this == obj)
		{
			return true;
		}
		if(obj == null)
		{
			return false;
		}
		if(!(obj instanceof User))
		{
			return false;
		}
		//
		return this.id.equals(((User)obj).id);
	}
	
	public String getRoleName()
	{
		if(role == ROLE_PROJECT_AUDIT)
		{
			return ROLE_PROJECT_AUDIT_NAME;
		}
		if(role == ROLE_PROJECT_DECLARE)
		{
			return ROLE_PROJECT_DECLARE_NAME;
		}
		if(role == ROLE_PROJECT_RECOMMEND)
		{
			return ROLE_PROJECT_RECOMMEND_NAME;
		}
		if(role == ROLE_SYS_ADMIN)
		{
			return ROLE_SYS_ADMIN_NAME;
		}
		return null;
	}
	
	public String getAreaName()
	{
		if(level == Area.LEVEL_PROVINCE){
			return "四川省";
		}
		if(level == Area.LEVEL_CITY){
			return "四川省" + city.getName();
		}
		if(level == Area.LEVEL_COUNTY){
			return "四川省" + city.getName() + county.getName();
		}
		return null;
	}
	
	//
	// Utilities.
	//
	public boolean isDeclarer()
	{
		return role == ROLE_PROJECT_DECLARE;
	}
	
	public boolean isRecommender()
	{
		return role == ROLE_PROJECT_RECOMMEND;
	}
	
	public boolean isAuditor()
	{
		return role == ROLE_PROJECT_AUDIT;
	}
	
	public boolean isSysAdmin()
	{
		return role == ROLE_SYS_ADMIN;				
	}
	//
	// Getters and Setters
	//
	public Integer getId()
	{
		return this.id;
	}
	
	public void setId(Integer id)
	{
		this.id = id;
	}

	public Integer getRole()
	{
		return role;
	}


	public void setRole(Integer role)
	{
		this.role = role;
	}


	public String getLoginName()
	{
		return this.loginName;
	}
	
	public void setLoginName(String loginName)
	{
		this.loginName = loginName;
	}
	
	public String getPswd()
	{
		return this.pswd;
	}
	
	public void setPswd(String pswd)
	{
		this.pswd = pswd;
	}
	
	public String getUnitName()
	{
		return this.unitName;
	}
	
	public void setUnitName(String unitName)
	{
		this.unitName = unitName;
	}
	
	public String getAddress()
	{
		return this.address;
	}
	
	public void setAddress(String address)
	{
		this.address = address;
	}
	
	public String getPhone()
	{
		return phone;
	}

	public void setPhone(String phone)
	{
		this.phone = phone;
	}

	public String getEmail()
	{
		return this.email;
	}
	
	public void setEmail(String email)
	{
		this.email = email;
	}

	public Integer getProvinceId()
	{
		return provinceId;
	}

	public void setProvinceId(Integer provinceId)
	{
		this.provinceId = provinceId;
	}

	public Integer getCityId()
	{
		return cityId;
	}

	public void setCityId(Integer cityId)
	{
		this.cityId = cityId;
	}

	public Integer getCountyId()
	{
		return countyId;
	}

	public void setCountyId(Integer countyId)
	{
		this.countyId = countyId;
	}

	public Integer getLevel()
	{
		return level;
	}

	public void setLevel(Integer level)
	{
		this.level = level;
	}

	public Area getProvince()
	{
		return province;
	}

	public void setProvince(Area province)
	{
		this.province = province;
	}

	public Area getCity()
	{
		return city;
	}

	public void setCity(Area city)
	{
		this.city = city;
	}

	public Area getCounty()
	{
		return county;
	}

	public void setCounty(Area county)
	{
		this.county = county;
	}


}
